package games.flvPlayer.ui
{
	import core.Global;
	
	import flash.events.Event;
	import flash.text.TextField;
	
	import games.flvPlayer.data.StreamManager;
	
	import interfaces.IAction;
	
	public class ShowTime implements IAction
	{
		/*
		参考
		http://www.51xflash.com/article/as3/201102/18-13389.html
		*/
		private var m_start:Boolean;
		private var m_pause:Boolean;
		
		private var m_stream:StreamManager;
		private var m_ui:TextField;
		
		public function ShowTime(sm:StreamManager)
		{
			m_stream = sm;
			m_stream.addEventListener(StreamManager.GET_METADATA,onGetTime);
		}
		
		public function set ui(n:TextField):void
		{
			m_ui = n;
			n.text = "00:00/00:00";
		}
		
		public function set start(b:Boolean):void
		{
			m_start = b;
		}
		
		public function get start():Boolean
		{
			return m_start;
		}
		
		public function set pause(b:Boolean):void
		{
		}
		
		public function get pause():Boolean
		{
			return m_pause;
		}
		
		public function update(t:Object=null):void
		{ 
			m_ui.text = timeFormat(m_stream.stream.time) +"/"+ timeFormat(m_stream.totalTime);  
		}
		
		private function onGetTime(e:Event):void
		{
			trace("总时长：",m_stream.totalTime);
			Global.addAction(this);
		}
		private function timeFormat(n:uint):String //时间（秒）转化格式为00：00  78.
		{  
			return String("0"+uint(n / 60)).substr(-2) + ":" + String("0" + n % 60).substr(-2);  
		}  
	}
}